<?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
$targetFolder = '/agilita/cms/uploads'; // Relative to the root



if (!empty($_FILES)) {
	
	$fileParts = pathinfo($_FILES['Filedata']['name']);
	
	$nome = uniqid();
	$ext = $fileParts['extension'];
	$nome = $nome . '.' . $ext;
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
	$targetFile = rtrim($targetPath,'/') . '/' . $nome  ;
	
	// Validate the file type
	$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
	
	
	if (in_array($fileParts['extension'],$fileTypes)) {
		move_uploaded_file($tempFile,$targetFile);
		echo $nome;
	} else {
		echo false;
	}
}
?>